<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>使用指定的键和值填充数组</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-diff.html">array_diff</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-fill.html">array_fill</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.array-fill-keys" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_fill_keys</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0)</p><p class="refpurpose"><span class="refname">array_fill_keys</span> &mdash; <span class="dc-title">使用指定的键和值填充数组</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.array-fill-keys-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>array_fill_keys</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$keys</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
   )</div>

  <p class="para rdfs-comment">

   使用 <em><code class="parameter">value</code></em> 参数的值作为值，使用 <em><code class="parameter">keys</code></em> 数组的值作为键来填充一个数组。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-fill-keys-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>


    
     <dt>
<em><code class="parameter">keys</code></em></dt>

     <dd>

      <p class="para">
       使用该数组的值作为键。非法值将被转换为<span class="type"><span class="type 字符串">字符串</span></span>。
      </p>
     </dd>

    

    
     <dt>
<em><code class="parameter">value</code></em></dt>

     <dd>

      <p class="para">
       填充使用的值。
      </p>
     </dd>

    

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-fill-keys-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回填充后的数组。
  </p>
 </div>




 <div class="refsect1 examples" id="refsect1-function.array-fill-keys-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4844">
    <p><strong>Example #1 <span class="function"><strong>array_fill_keys()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$keys&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_fill_keys</span><span style="color: #007700">(</span><span style="color: #0000BB">$keys</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'banana'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [foo] =&gt; banana
    [5] =&gt; banana
    [10] =&gt; banana
    [bar] =&gt; banana
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-fill-keys-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.array-fill.html" class="function" rel="rdfs-seeAlso">array_fill()</a> - 用给定的值填充数组</span></li>
    <li class="member"><span class="function"><a href="function.array-combine.html" class="function" rel="rdfs-seeAlso">array_combine()</a> - 创建一个数组，用一个数组的值作为其键名，另一个数组的值作为其值</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-diff.html">array_diff</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-fill.html">array_fill</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
